import {get, post, del, put} from '@/common/js/httpHelper'
import {ROLE_URL} from '@/common/js/interfaces'

const getRoleAndAuthorization = async (loadCondition) => {
  let roleAndAuthorizationData = await post(ROLE_URL + '/list', loadCondition)
  return roleAndAuthorizationData.data
}

const addRole = async (params) => {
  return await post(ROLE_URL + '/add', params)
}

const updateRole = async (role) => {
  return await put(ROLE_URL + '/update', role)
}

const delRole = async (roleId) => {
  return await del(ROLE_URL + '/del/' + roleId)
}

const addRoleAuthorization = async (params) => {
  return await post(ROLE_URL + '/add/authorization', params)
}

const delRoleAuthorization = async (roleAuthorizationId) => {
  const result = await del(ROLE_URL + '/del/authorization/' + roleAuthorizationId)
  return result.data
}

const getRoleAuthorizationByRoleId = async (roleId) => {
  return await get(ROLE_URL + '/find/roleAuthorizations/' + roleId)
}

export default {
  delRoleAuthorization: delRoleAuthorization,
  addRoleAuthorization: addRoleAuthorization,
  delRole: delRole,
  updateRole: updateRole,
  addRole: addRole,
  getRoleAndAuthorization: getRoleAndAuthorization,
  getRoleAuthorizationByRoleId: getRoleAuthorizationByRoleId
}
